﻿using System;
using SpCop.Core.Model;
using SpCop.Model;

namespace SpCop
{
    public abstract class ModuleRuleBase : ElementRuleBase
    {
        private readonly Predicate<string> _moduleFilter;

        protected ModuleRuleBase() : base(a => a.ElementType == ElementType.Module)
        {
            _moduleFilter = (r) => true;
            
        }

        protected ModuleRuleBase(Predicate<string> moduleFilter)
            : base(a => a.ElementType == ElementType.Module)
        {
            _moduleFilter = moduleFilter;
        }

       
        protected override void VisitElement(Package package, Feature feature, Element item)
        {
            string moduleUrl = item.Xml.Attribute("Url").Value;
            if (_moduleFilter(moduleUrl))
                VisitModule(package, feature, item);
        }


        protected virtual void VisitModule(Package package, Feature feature, Element item)
        {
        }
    }
}